
/**
@description 数组转字符串
@param array 数组
@param separator 连接符
*/
export const arrayToString = (
  array: string[],
  separator: string = ",",
): string => {
  if (array && array.length > 0) {
    let result: string = "";
    array.map((r) => {
      result += r + separator;
    });
    //删除最后一个逗号
    if (result.indexOf(separator) > -1) {
      result = result.substring(0, result.length - 1);
    }
    return result;
  }
  return "";
};

/**
 *
 * @param bytes 文件长度
 * @returns
 */
export function formatFileSize(bytes: number) {
  if (bytes === 0) return "0 B";
  const units = ["B", "KB", "MB", "GB", "TB"];
  const unitIndex = Math.floor(Math.log(bytes) / Math.log(1024));
  const size = (bytes / Math.pow(1024, unitIndex)).toFixed(2);
  return `${parseFloat(size)} ${units[unitIndex]}`; // 移除末尾的.00
}
